#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=200005;

int n,m;
vector<int> edges[N];
LL w[N];
LL d1[N],d2[N];
int ms[N];
LL w0,maxn=0;
int ansi;

void dfs(int son,int fa){
	d1[son]=d2[son]=0;
	ms[son]=0;
	int size=edges[son].size();
	for(int i=0;i<size;i+=2){
		int u=edges[son][i],j=edges[son][i+1];
		if(u==fa) continue;
		dfs(u,son);
		LL t=d1[u]+w[j];
		//printf("%d %d %lld\n",u,son,t);
		if(t>d1[son]){
			d2[son]=d1[son];
			d1[son]=t;
			ms[son]=u;
		}
		else if(t>d2[son]){
			d2[son]=t;
		}
	};
	if(d1[son]+d2[son]>=maxn){
		maxn=d1[son]+d2[son];
		ansi=son;
	}
}
int main(){
	scanf("%d%d",&n,&m);
	int s,t;
	for(int i=0;i<m;i++){
		scanf("%d%d%lld",&s,&t,&w[i]);
		edges[s].emplace_back(t);
		edges[s].emplace_back(i);
		edges[t].emplace_back(s);
		edges[t].emplace_back(i);
	}
	dfs(1,0);
	LL ans=0,cur=d2[ansi];
	int j=ansi;
	//printf("%d %lld %lld\n",j,cur,maxn);
	for(;ms[j]!=0;j=ms[j]){
		int size=edges[j].size();
		for(int k=0;k<size;k+=2){
			if(edges[j][k]==ms[j]){
				cur+=w[edges[j][k+1]];
				break;
			}
		}
		ans=max(ans,min(cur,maxn-cur));
		//printf("%lld %lld\n",cur,ans);		
	}
	printf("%lld",ans+maxn);
	return 0;
}
/*
4 3
1 2 3
2 3 4
3 4 7
*/
